﻿<Window x:Class="WgpgGUI.DialogTasks"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:WgpgGUI"
        Icon="/WgpgCore;component/Images/running.png"
        Title="Running Tasks" Height="384" Width="315">
    
    <Window.Resources>
        <DataTemplate x:Key="itemsTemplate">
            <Grid Width="Auto" Height="Auto" Margin="10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" FontWeight="Bold" Text="{Binding Name}"/>
                <TextBlock Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding Description}" TextWrapping="Wrap"/>
                <ProgressBar Name="ProgressBar" Height="20" Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" IsIndeterminate="True" Margin="0 0 10 0" Minimum="0" Maximum="100"/>
                <Button Name="CancelButton" Margin="0" Grid.Column="1" Grid.Row="3" Content="_Abort" VerticalAlignment="Center" Tag="{Binding}" Click="AbortTask"/>
            </Grid>
            
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Status}" Value="Error">
                    <Setter TargetName="ProgressBar" Property="Foreground" Value="Red"/>
                    <Setter TargetName="ProgressBar" Property="Value" Value="100"/>
                    <Setter TargetName="ProgressBar" Property="IsIndeterminate" Value="False"/>
                    <Setter TargetName="CancelButton" Property="IsEnabled" Value="False"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Success">
                    <Setter TargetName="ProgressBar" Property="Value" Value="100"/>
                    <Setter TargetName="ProgressBar" Property="IsIndeterminate" Value="False"/>
                    <Setter TargetName="CancelButton" Property="IsEnabled" Value="False"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="NotStarted">
                    <Setter TargetName="ProgressBar" Property="Value" Value="0"/>
                    <Setter TargetName="ProgressBar" Property="IsIndeterminate" Value="False"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </Window.Resources>
    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ScrollViewer VerticalScrollBarVisibility="Auto">
            <ItemsControl Grid.Column="0" Grid.Row="0" Name="TaskList" Width="Auto" Height="Auto" ItemsSource="{Binding}" ItemTemplate="{StaticResource itemsTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </ScrollViewer>

        <StackPanel Grid.Column="0" Grid.Row="1" Background="#F0F0F0" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
            <Border BorderBrush="#DFDFE0" Height="1" BorderThickness="1"/>
            <DockPanel>
                <Button Content="Clear List" Click="ClearListButton" Margin="10"/>
                <Button Content="_Close" HorizontalAlignment="Right" Click="Close"/>
            </DockPanel>
        </StackPanel>
    </Grid>
</Window>
